package com.ccf.business.source.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.common.utils.tool.UserUtil;
import com.service.mybatis.pojo.SuperEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;


/**
 * 文件中心
 *
 * @author ccf
 * @date 2022-02-15 14:20:52
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@TableName("kcs_source")
@ApiModel(value="kcs_source对象", description="文件中心")
public class Source extends SuperEntity {
    private static final long serialVersionUID=1L;

    public static final int MAX_FILE_NAME_LENGTH = 100;
    @ApiModelProperty(value = "文件夹名称")
    private String name;

    public static final String ROOT = "0";
    @ApiModelProperty(value = "父文件夹id(根目录为0)")
    private String pid = ROOT;

    @ApiModelProperty(value = "创建人")
    @TableField(fill = FieldFill.INSERT)
    @JSONField(label = UserUtil.USER_LABEL)
    private String creator;

    public static final String FOLDER_TYPE = "folder";
    public static final String FOLDER_TYPE_STR = "文件夹";
    @ApiModelProperty(value = "文件类型（folder：文件夹）")
    private String fileType;

    @ApiModelProperty(value = "文件大小")
    private String fileSize;

    public static final int READY = 0;
    public static final int UPLOAD = 1;
    public static final int UPLOAD_SUCCESS = 2;
    public static final int UPLOAD_CANCEL = -2;
    public static final int UPLOAD_FAIL = -1;
    @ApiModelProperty(value = "上传状态(上传中、上传成功、已取消、上传失败)")
    private Integer uploadStatus;

    @ApiModelProperty(value = "文件存储地址")
    private String path;

    @ApiModelProperty(value = "文件预览路径")
    @TableField(exist = false)
    private String viewPath;

    public static final String ALL = "全部";
    @ApiModelProperty(value = "分类")
    @TableField(exist = false)
    private String classify;

    public boolean isDirectory(){
        return FOLDER_TYPE.equalsIgnoreCase(fileType);
    }

    public String getStatus() {
        if (uploadStatus == null){
            return "";
        }
        switch (uploadStatus){
            case UPLOAD:
                return "上传中";
            case UPLOAD_CANCEL:
                return "已取消";
            case UPLOAD_FAIL:
                return "上传失败";
            default:
                return "上传完成";
        }
    }

    public String getStatusCode() {
        if (uploadStatus == null){
            return "";
        }
        switch (uploadStatus){
            case READY:
                return "ready";
            case UPLOAD:
                return "uploading";
            case UPLOAD_CANCEL:
                return "cancel";
            case UPLOAD_FAIL:
                return "fail";
            default:
                return "success";
        }
    }
}
